Modify and Existing Enumerated Attribute

I know, I know. I read the latest forum discussions on this topic and thought I had a slam dunk, as far as updating an enumerated attribute in several modules, based on updates that were made to it in the "original" module. I used the Help files and this forum, but I still get a syntax error with the modify call. I have an enum named "Category", of base type "Enumeration" and I combined the available snippets from the Help files to come up with the following, for updating the "Category" attribute so that the list of available choices includes the seven items listed below:
//start script
Module m = current
AttrType atype = find(m,"Category")
string sBaseType = stringOf(atype.type)
if(sBaseType == "Enumeration")
{
setRealColorOptionForTypes (true)
AttrType modify(atype,"Category",,0,1,2,3,4,5,6,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,"")
}
//end script
The modify line above is based on the suggested approach from the Help files if you want to modify an existing enumerated attribute, as follows:
AttrType modify(AttrType type,string newName,string codes[ ],int values[ ],int colors[ ],int arrMaps[ ],string &errmess)
What's wrong with my syntax?

Thanks a bunch!! This forum has never failed me!!
Chris
ChrisAnnal - Thu Jul 23 18:35:13 EDT 2009

Re: Modify and Existing Enumerated Attribute
ChrisAnnal - Thu Jul 23 18:38:32 EDT 2009

For some reason, certain portions of the contents of the modify function didn't appear in the text body of my question, so I'm attaching the actual (but still not working) script here.
Attachments

attachment_14277835_Modify_Enumerated_Type.dxl

Re: Modify and Existing Enumerated Attribute
llandale - Fri Jul 24 11:19:35 EDT 2009

ChrisAnnal - Thu Jul 23 18:38:32 EDT 2009
For some reason, certain portions of the contents of the modify function didn't appear in the text body of my question, so I'm attaching the actual (but still not working) script here.

[1] It doesn't like using constant arrays as parameters. You'll need to define your arrays as variables and then use them as parameters.

[2] You need to assign the 'modify' to a variable.

[3] I don't know what will happen when you get an error message (last parameter) and the function assigns it to you null string constant. That cannot be good. Use an ErrMess variable.

Module m = current 
AttrType atype = find(m,"Category")
string sBaseType = stringOf(atype.type) 
if(sBaseType == "Enumeration")
{
   string Codes[] = {"Literature","Rack","Standup","What","Parent","Phase 2","N/A")
   int    Valus[] = {0,1,2,3,4,5,6}
   int   Color[] = {-1,-1,-1,-1,-1,-1,-1}
   int    Map[]  = {0,1,2,3,4,5,6}
   string ErrMess = ""
 
 
   setRealColorOptionForTypes (true)
   AttrType atNew = modify(atype,"Category", Codes, Valus, Color, Map, ErrMess)
   // if (null atNew or !null ErrMess) we got an error
                
}

 

 

  • Louie

 

 

Re: Modify and Existing Enumerated Attribute
ChrisAnnal - Tue Jul 28 10:00:41 EDT 2009

llandale - Fri Jul 24 11:19:35 EDT 2009

[1] It doesn't like using constant arrays as parameters. You'll need to define your arrays as variables and then use them as parameters.

[2] You need to assign the 'modify' to a variable.

[3] I don't know what will happen when you get an error message (last parameter) and the function assigns it to you null string constant. That cannot be good. Use an ErrMess variable.

Module m = current 
AttrType atype = find(m,"Category")
string sBaseType = stringOf(atype.type) 
if(sBaseType == "Enumeration")
{
   string Codes[] = {"Literature","Rack","Standup","What","Parent","Phase 2","N/A")
   int    Valus[] = {0,1,2,3,4,5,6}
   int   Color[] = {-1,-1,-1,-1,-1,-1,-1}
   int    Map[]  = {0,1,2,3,4,5,6}
   string ErrMess = ""
 
 
   setRealColorOptionForTypes (true)
   AttrType atNew = modify(atype,"Category", Codes, Valus, Color, Map, ErrMess)
   // if (null atNew or !null ErrMess) we got an error
                
}

 

 

  • Louie

 

 

Hi Louie!!

That pretty much did the trick, thanks!! There was a slight modification because DOORS didn't like the variables being declared in the body of the "if" statement, and for some reason, I had to use parenthesis ( ) instead of curly braces { } for the values of string codes, but it worked like a charm!! Here's what I ended up with. It runs super fast in an open module. Thanks again!!
Chris

// <Modify Enumerated Type.dxl> - Modify an existing Enumerated attribute.
/*

To modify this script, simply change the attribute type "Category" in the two places
where it appears in the script below to the name of the existing enumerated attribute
you want to modify. Also, for the codes in parenthesis below, change the items in
parenthesis "Literature", "Rack", etc to the actual ones you want to use.
For colors, "-1" means you don't want to change them, whatever they are. This script
assumes 7 values are being changed, and that they are listed starting at the number "0".
It's important to keep the same number of items for each variable. That is, if you add to
the list or shorten it, you should do the same for all the variables, to keep them in
synch.

*/
Module m = current
AttrType atype = find(m,"Category")
string sBaseType = stringOf(atype.type)
string codes[]= ("Literature","Rack","Standup","What","Parent","Phase 2","N/A")
int values[] = {0,1,2,3,4,5,6}
int colors[] = {-1,-1,-1,-1,-1,-1,-1}
int arrMaps[] = {0,1,2,3,4,5,6}
string ErrMess = ""
if(sBaseType == "Enumeration")
{
setRealColorOptionForTypes (true)
AttrType atNew = modify(atype,"Category", codes, values, colors, arrMaps, ErrMess)
// if (null atNew or !null ErrMess) we got an error
}
P.S. How did you get your text to be "colorized" in your reply? That's pretty cool.

Re: Modify and Existing Enumerated Attribute
llandale - Tue Jul 28 10:07:42 EDT 2009

ChrisAnnal - Tue Jul 28 10:00:41 EDT 2009
Hi Louie!!

That pretty much did the trick, thanks!! There was a slight modification because DOORS didn't like the variables being declared in the body of the "if" statement, and for some reason, I had to use parenthesis ( ) instead of curly braces { } for the values of string codes, but it worked like a charm!! Here's what I ended up with. It runs super fast in an open module. Thanks again!!
Chris

// <Modify Enumerated Type.dxl> - Modify an existing Enumerated attribute.
/*

To modify this script, simply change the attribute type "Category" in the two places
where it appears in the script below to the name of the existing enumerated attribute
you want to modify. Also, for the codes in parenthesis below, change the items in
parenthesis "Literature", "Rack", etc to the actual ones you want to use.
For colors, "-1" means you don't want to change them, whatever they are. This script
assumes 7 values are being changed, and that they are listed starting at the number "0".
It's important to keep the same number of items for each variable. That is, if you add to
the list or shorten it, you should do the same for all the variables, to keep them in
synch.

*/
Module m = current
AttrType atype = find(m,"Category")
string sBaseType = stringOf(atype.type)
string codes[]= ("Literature","Rack","Standup","What","Parent","Phase 2","N/A")
int values[] = {0,1,2,3,4,5,6}
int colors[] = {-1,-1,-1,-1,-1,-1,-1}
int arrMaps[] = {0,1,2,3,4,5,6}
string ErrMess = ""
if(sBaseType == "Enumeration")
{
setRealColorOptionForTypes (true)
AttrType atNew = modify(atype,"Category", codes, values, colors, arrMaps, ErrMess)
// if (null atNew or !null ErrMess) we got an error
}
P.S. How did you get your text to be "colorized" in your reply? That's pretty cool.

Its not just colorized, its also properly indented and using non-proportional font spacing. Insert {code} before and after your code.

Surprised it doesn't like the arrays declared inside the 'if'. I never do that anyway.

  • Louie

Re: Modify and Existing Enumerated Attribute
SystemAdmin - Thu Jan 26 15:48:21 EST 2012

llandale - Tue Jul 28 10:07:42 EDT 2009
Its not just colorized, its also properly indented and using non-proportional font spacing. Insert {code} before and after your code.

Surprised it doesn't like the arrays declared inside the 'if'. I never do that anyway.

  • Louie

I need to replace the current enumerated attributes of the module, without affecting their position and the current definition selection. Is it possible to replicate the replace function?

Re: Modify and Existing Enumerated Attribute
llandale - Fri Jan 27 09:45:57 EST 2012

SystemAdmin - Thu Jan 26 15:48:21 EST 2012
I need to replace the current enumerated attributes of the module, without affecting their position and the current definition selection. Is it possible to replicate the replace function?

Are you saying you want to change:
  • "Cold", "Medium", "Hot" to
  • "Cool", "Moderate", "Scalding"?

Use the above techniques where your "matching" array matches positions exactly:
  • {0, 1, 2}

-Louie

Re: Modify and Existing Enumerated Attribute
SystemAdmin - Mon Jan 30 09:13:02 EST 2012

llandale - Fri Jan 27 09:45:57 EST 2012
Are you saying you want to change:

  • "Cold", "Medium", "Hot" to
  • "Cool", "Moderate", "Scalding"?

Use the above techniques where your "matching" array matches positions exactly:
  • {0, 1, 2}

-Louie

Thanks for all the information provided...I was able to create something that will allow me to loop thru all related module and make the changes to the attribute without having to compromise the data.

//This program was intended to replace the values of an enumerated attribute
//The replace will not affect the current selected values, it will just change the value to the new one
 
pragma runLim, 0
 
void replaceAttributeTypeValue(Module m, string atName, string oldVal, string newVal){
    AttrType att = find(m, atName)
        //Declare Arrays Size
        int colores[att.size]
        int arrMap[att.size]
        string arr[att.size]
        int arrVal[att.size]
        
        int i
        //Populate Arrays
        for(i = 0; i < att.size; i++){ 
                arr[i] = att.strings[i]
                arrVal[i] = i
                colores[i] = -1
                arrMap[i] = i
        }
        //
        for(i = 0; i < sizeof(arr); i++){ 
                if(arr[i] == oldVal){
                        arr[i] = newVal
                }
        }
 
        string err = null
        AttrType at2 = modify(att, "Allocation", arr, arrVal, colores, arrMap, err)
        if(!null err){
                print "Failed: " err"\n"
        }
        else{
                infoBox at2.name " - Modified Successfully"
        }
}

Re: Modify and Existing Enumerated Attribute
SystemAdmin - Mon Jan 30 09:31:37 EST 2012

llandale - Fri Jan 27 09:45:57 EST 2012
Are you saying you want to change:

  • "Cold", "Medium", "Hot" to
  • "Cool", "Moderate", "Scalding"?

Use the above techniques where your "matching" array matches positions exactly:
  • {0, 1, 2}

-Louie

One more question...What if I want to remove/delete a value?
There is nothing in the DXL Reference Manual with this information.

Re: Modify and Existing Enumerated Attribute
llandale - Mon Jan 30 18:47:27 EST 2012

SystemAdmin - Mon Jan 30 09:13:02 EST 2012

Thanks for all the information provided...I was able to create something that will allow me to loop thru all related module and make the changes to the attribute without having to compromise the data.

//This program was intended to replace the values of an enumerated attribute
//The replace will not affect the current selected values, it will just change the value to the new one
 
pragma runLim, 0
 
void replaceAttributeTypeValue(Module m, string atName, string oldVal, string newVal){
    AttrType att = find(m, atName)
        //Declare Arrays Size
        int colores[att.size]
        int arrMap[att.size]
        string arr[att.size]
        int arrVal[att.size]
        
        int i
        //Populate Arrays
        for(i = 0; i < att.size; i++){ 
                arr[i] = att.strings[i]
                arrVal[i] = i
                colores[i] = -1
                arrMap[i] = i
        }
        //
        for(i = 0; i < sizeof(arr); i++){ 
                if(arr[i] == oldVal){
                        arr[i] = newVal
                }
        }
 
        string err = null
        AttrType at2 = modify(att, "Allocation", arr, arrVal, colores, arrMap, err)
        if(!null err){
                print "Failed: " err"\n"
        }
        else{
                infoBox at2.name " - Modified Successfully"
        }
}

So you can change "Medium" to "Moderate". OK.

You probably want to preserve the other information as is:

.
    for(i = 0; i < att.size; i++){ 
                arr[i] = att.strings[i]
                arrVal[i] = att.values()
                colores[i] = att.colors()
                arrMap[i] = i
        }


For v93 you want to preserve the new 'Descriptions' as well, which is another array:
arrDesc[i] = att.descriptions()

Sure you can figure out where to put arrDesc in your "modify" command.

I have a nagging memory of there being some color command you must issue before setting colors of enumerated attributes;

 

  • setRealColorOptionForTypes(true)

maybe you can verify or contradict that.

-Louie

I'm strongly in favor of putting this sort of thing into a function as you did. Once you get it to work then you can either deploy in a library, or have something to copy-paste into whatever program you want, and don't have to worry about tweaking it to get it to work.